
package flc.ast.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;
import com.stark.translator.util.LanCodeUtil;

import flc.ast.R;
import flc.ast.adapter.LanguageAdapter;
import stark.common.other.LanCode;

public class LanguageDialog extends AttachPopupView implements View.OnClickListener {

    private RecyclerView recyclerView;
    private LanguageAdapter languageAdapter;

    public LanguageDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_language_style;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        recyclerView = findViewById(R.id.rvLanguageList);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        languageAdapter = new LanguageAdapter();
        recyclerView.setAdapter(languageAdapter);
        languageAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                LanCode lanCode = languageAdapter.getItem(position);
                if (listener != null) {
                    dismiss();
                    listener.clickSelLan(lanCode);
                }
            }
        });
        languageAdapter.setList(LanCodeUtil.getAllLanCodes());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickSelLan(LanCode lanCode);
    }

}
